using System.Collections.Generic;
using UnityEngine;

namespace NL.Advanced
{

    public class UICamera : _OwnerOf<Camera>
    {

        public bool ParentAsNull = true;
        public Vector3 Repos = Vector3.up * 9999;


        public float OrthographicSize => Owner.orthographicSize;



        public bool SetIsDefaultInstance = false;
        // Start is called before the first frame update

        static Dictionary<string, UICamera> _ALL = new Dictionary<string, UICamera>();
        public static Camera MAIN;

        public static UICamera INSTANCE_Of(string name)
        {
            return _ALL.ContainsKey(name) ? _ALL[name] : null;
        }
        protected override void Awake()
        {
            base.Awake();

            if (SetIsDefaultInstance)
                MAIN = _Owner;

            if (_ALL.ContainsKey(name))
                _ALL[name] = this;
            else
                _ALL.Add(name, this);

            if (ParentAsNull)
            {
                transform.SetParent(null);
                transform.localPosition = Repos;
                transform.localRotation = Quaternion.identity;
                transform.localScale = Vector3.one;
            }

        }
        private void OnDestroy()
        {
            if (_ALL.ContainsKey(name) && _ALL[name] == this)
                _ALL.Remove(name);
        }

        //private void Start()
        //{
        //    //UI.Instance.SetCamera(RenderMode.ScreenSpaceCamera, MAIN);


        //    try
        //    {
        //        var UIHeight = UI.Instance.GetComponent<CanvasScaler>().referenceResolution.y;
        //        Owner.orthographicSize = UIHeight * 0.5f;
        //    }
        //    catch(Exception e)
        //    {

        //    }
        //}


    }
}

